package eao;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entity.Person;

/**
 * Session Bean implementation class EaoUser
 */
@Stateless(mappedName = "eaoPerson")
@LocalBean
public class EaoPerson {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public EaoPerson() {
        // TODO Auto-generated constructor stub
    }
    

    public Person find(int id) {
        return em.find(Person.class, id);
    }

    public List<Person> list() {
    	return em.createQuery("SELECT p FROM Person p", Person.class).getResultList();
    }

    public void create(Person person) {
        	em.persist(person);
    }

    public void update(Person person) {
        em.merge(person);
    }

    public void delete(Person person) {
        em.remove(em.contains(person) ? person : em.merge(person));
    }

}
